<template>
	<view class="container">
		<scroll-view scroll-y="true" class="goods-container" v-if="list.length>0" @scrolltolower="loadMore">
			<view style="height: 20rpx;"></view>
			<view class="goods-items">
				<my-waterfalls-goods :list="list"></my-waterfalls-goods>
			</view>
			<u-loadmore :status="hasMore?'loading':'nomore'" />
		</scroll-view>
		<view class="empty-container" v-else>
			<u-empty text="暂无相关商品" :icon="emptyIcon"/>
		</view>
	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				emptyIcon:'https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/common/empty.png',
				hasMore:true,
				pageIndex:1,
				list:[],
				is_recommend:0,
				is_seckill:0,
				cate_id:0,
			};
		},
		methods: {
			loadMore(){
				if(_this.hasMore){
					_this.pageIndex++
					_this.get_list()
				}
			},
			async get_list(){
				const params = {
					pageIndex: this.pageIndex,
					pageSize:20,
					is_recommend:_this.is_recommend,
					is_seckill:_this.is_seckill,
					cate_id:_this.cate_id,
				}
				const data = await _this.$post('api/get_goods',params)
				if(data.code==200){
					this.list.push(...data.data.list)
					this.hasMore=data.data.list.length>=20
				}else{
					this.hasMore=false
				}
			},
		},
		onLoad(e) {
			_this = this;
			if(e.is_recommend){
				_this.is_recommend=e.is_recommend
				uni.setNavigationBarTitle({
					title:'商城推荐'
				})
			}
			if(e.is_seckill){
				_this.is_seckill=e.is_seckill
				uni.setNavigationBarTitle({
					title:'秒杀专区'
				})
			}
			if(e.cate_id){
				_this.cate_id=e.cate_id
				uni.setNavigationBarTitle({
					title:'商品列表'
				})
			}
			_this.get_list()
		},
		onShow() {

		},
		components: {}
	}
</script>

<style lang="scss" scoped>
	.container {
		height: 100%;
		padding: 0;
		.goods-container{
			height: calc(100%);
			box-sizing: border-box;
			.goods-items{
				padding: 0 30rpx;
			}
		}
	}
</style>
